package com.tlias.controller;

import com.tlias.pojo.Dept;
import com.tlias.pojo.Emp;
import com.tlias.pojo.PageBean;
import com.tlias.pojo.Result;
import com.tlias.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    private EmpService empService;

    //条件分页查询
    @GetMapping()
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       String name, Short gender,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end) {
        //记录日志
        log.info("分页查询，参数：{},{},{},{},{},{}", page, pageSize, name, gender, begin, end);
        // 调用业务层分页查询功能
        PageBean pageBean = empService.page(page, pageSize, name, gender, begin, end);
        // 响应
        return Result.success(pageBean);
    }

    //根据id删除
    @DeleteMapping("/{ids}")
    public Result deleteEmp(@PathVariable List<Integer> ids) {
        log.info("根据id删除删除");
        empService.delete(ids);
        return Result.success();
    }

    //添加数据
    @PostMapping
    public Result addEmp(@RequestBody Emp emp) {
        log.info("添加数据");
        empService.addEmp(emp);
        return Result.success();
    }

    //修改数据
    @PutMapping
    public Result updateEmp(@RequestBody Emp emp) {
        log.info("修改数据");
        empService.updateEmp(emp);
        return Result.success();
    }

    //根据id查找数据
    @GetMapping("/{id}")
    public Result findEmp(@PathVariable Integer id) {
        log.info("根据id查找数据");
        Emp emp = empService.findEmp(id);

        return Result.success(emp);
    }





}


